var a = require("../../requests/request.js");

getApp();

Page({
    data: {
        currentMainTab: 5,
        monthList: [],
        yearList: [],
        newCarList: [],
        totalCount: 0,
        pageindex: 1,
        pagesize: 10,
        showMessage: "",
        hothidden: !1,
        winHeight: 0,
        pagesource: ""
    },
    setHaveDataTime: function() {
        var t = this;
        a.getHaveDataTime(function(a) {
            var e = a;
            t.setData({
                monthList: new Array(e.Data[0].Month, e.Data[1].Month, e.Data[2].Month, e.Data[3].Month, e.Data[4].Month, e.Data[5].Month),
                yearList: new Array(e.Data[0].Year, e.Data[1].Year, e.Data[2].Year, e.Data[3].Year, e.Data[4].Year, e.Data[5].Year)
            });
            var n = t.data.yearList[t.data.currentMainTab] + "上市新车";
            wx.setNavigationBarTitle({
                title: n
            }), t.getnewCarList();
        }, function(a) {}, function(a) {});
    },
    onShareAppMessage: function() {
        return {
            title: "上市新车，在线查询汽车报价、车型参数、汽车图片和汽车资讯",
            path: "/pages/newcar/newcar?pagesource=wxshare"
        };
    },
    getnewCarList: function() {
        var t = this, e = t.data.yearList[t.data.currentMainTab], n = t.data.monthList[t.data.currentMainTab];
        a.getNewCarList(e, n, t.data.pageindex, t.data.pagesize, function(a) {
            var e = a;
            t.setData({
                newCarList: t.data.newCarList.concat(e.Data.List),
                pageindex: t.data.pageindex + 1,
                totalCount: e.Data.Total
            }), 0 == t.data.Total ? t.setData({
                showMessage: "本月无上市新车"
            }) : t.setData({
                showMessage: ""
            });
        }, function(a) {}, function(a) {});
    },
    swichNav: function(a) {
        var t = this;
        if (this.data.currentMainTab === a.currentTarget.dataset.current) return !1;
        t.setData({
            currentMainTab: a.currentTarget.dataset.current,
            newCarList: [],
            pageindex: 1
        });
        var e = t.data.yearList[t.data.currentMainTab] + "上市新车";
        wx.setNavigationBarTitle({
            title: e
        }), t.getnewCarList();
    },
    clickCar: function(a) {
        var t = a.currentTarget.dataset.id, e = a.currentTarget.dataset.name;
        wx.navigateTo({
            url: "../summary/summary?id=" + t + "&name=" + e
        });
    },
    getBestSellData: function() {
        var a = this;
        a.data.hothidden ? a.setData({
            hothidden: !1
        }) : (a.setData({
            hothidden: !0
        }), a.getnewCarList(), a.setData({
            hothidden: !1
        }));
    },
    swiperchange: function(a) {
        var t = this;
        t.setData({
            currentMainTab: a.detail.current,
            newCarList: [],
            pageindex: 1
        });
        var e = t.data.yearList[t.data.currentMainTab] + "上市新车";
        wx.setNavigationBarTitle({
            title: e
        });
    },
    onLoad: function(a) {
        var t = this, e = "";
        a.pagesource && (e = a.pagesource), wx.getSystemInfo({
            success: function(a) {
                t.setData({
                    winHeight: a.windowHeight,
                    pagesource: e
                });
            }
        });
    },
    onShow: function() {},
    onReady: function(a) {
        this.setHaveDataTime();
    }
});